package vip.meeet.concurrent.pool;

import java.util.concurrent.ExecutionException;
import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;
import java.util.concurrent.Future;

public class ThreadPoolExecutorExceptionStack {
    
    
    public static void main(String[] args) {
        int cpu = Runtime.getRuntime().availableProcessors();
        ExecutorService pool = Executors.newFixedThreadPool(cpu);
        for(int i=0;i<5;i++){
            BadDiv badDiv = new BadDiv(5,i);
            Future<?> result = pool.submit(badDiv);
            try {
                result.get();
            } catch (InterruptedException e) {
                e.printStackTrace();
            } catch (ExecutionException e) {
                e.printStackTrace();
            }
        }
    }
    
    static class BadDiv implements Runnable{

        int a,b;
        
        BadDiv(int a,int b){
            this.a = a;
            this.b = b;
        }
        @Override
        public void run() {
            int result = a/b;
            System.out.println(result);
        }
        
    }

}
